package com.theme.passport.controller.sys;

import com.theme.common.mvc.utils.PageUtils;
import com.theme.common.mvc.view.R;
import com.theme.passport.entity.constant.ThemeStatusEnum;
import com.theme.passport.service.theme.RecommendProductService;
import com.theme.passport.service.theme.ThemeService;
import com.theme.passport.service.theme.WallpaperService;
import com.theme.passport.service.theme.WidgeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 今日推荐
 *
 * @author live
 * @email 870459550@qq.com
 * @date 2020-12-08 15:14:01
 */
@RestController
@RequestMapping("sys/recommend-product")
public class SysRecommendProductController {

    @Autowired
    private ThemeService themeService;

    @Autowired
    private WallpaperService wallpaperService;

    @Autowired
    private WidgeService widgeService;

    @Autowired
    private RecommendProductService recommendService;

    /**
     * 所有主题
     */
    @RequestMapping("/themeList")
    @RequiresPermissions("sys:recommend:list")
    public R themeList(@RequestParam Map<String, Object> params){
        Integer status = ThemeStatusEnum.NORMAL.getValue();
        params.put("status",status +"");
        PageUtils page = themeService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 所有组件
     */
    @RequestMapping("/widgeList")
    @RequiresPermissions("sys:recommend:list")
    public R widgeList(@RequestParam Map<String, Object> params){
        Integer status = ThemeStatusEnum.NORMAL.getValue();
        params.put("status",status +"");
        params.put("themeShow", false);
        PageUtils page = widgeService.queryPageByDistinctName(params);
        return R.ok().put("page", page);
    }

    /**
     * 所有壁纸
     */
    @RequestMapping("/wallpaperList")
    @RequiresPermissions("sys:recommend:list")
    public R wallpaperList(@RequestParam Map<String, Object> params){
        Integer status = ThemeStatusEnum.NORMAL.getValue();
        params.put("status",status +"");
        PageUtils page = wallpaperService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 今日推荐主题
     */
    @RequestMapping("/selectedList")
    @RequiresPermissions("sys:recommend:list")
    public R selectedList(@RequestParam Map<String, Object> params){
        PageUtils page = recommendService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:recommend:update")
    public R update(@RequestBody Long[] ids,
                    @RequestParam("type") Integer type,
                    @RequestParam("recommendId") Long recommendId){
        List<Long> objIds = Arrays.asList(ids);
        //先全部删除，然后重新插入：
        recommendService.updateRecommendProduct(objIds, type,recommendId);
        return R.ok();
    }

}
